<!DOCTYPE html>
<!-- saved from url=(0039)https://gist.github.com/Arthraim/994641 -->
<html class=" js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms no-csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths filereader" style=""><head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>a python web framework bottle's example</title>

  <meta content="authenticity_token" name="csrf-param">
<meta content="78hRzy9jZQQRPL2IkVnwp9z6tlzJNuSqednXYkKG664=" name="csrf-token">
  <meta name="viewport" content="width=960">

  <link type="text/plain" rel="author" href="https://github.com/humans.txt">

  <meta content="gist" name="octolytics-app-id"><meta content="collector.githubapp.com" name="octolytics-host">

  <link href="https://gist.github.com/assets/application-1a163d807985dac0d994594ef2558571.css" media="screen, print" rel="stylesheet">
  <script src="./a python web framework bottle's example_files/application-7d8a13b069fc44ac7cae88ab43791eeb.js"></script><script type="text/javascript" async="" src="./a python web framework bottle's example_files/ga.js"></script>

    <meta name="twitter:card" content="summary">
  <meta name="twitter:site" content="@github">
  <meta property="og:title" content="Arthraim/bottle_example.py">
  <meta property="og:type" content="githubog:gist">
  <meta property="og:url" content="#{Gists.url}/Arthraim/994641">
  <meta property="og:image" content="https://secure.gravatar.com/avatar/a0eef010278ab0859ea2424aea0f1e28?s=140&amp;d=https://github.com/images/gravatars/gravatar-140.png">
  <meta property="og:site_name" content="GitHub Gists">
  <meta property="og:description" content="a python web framework bottle&amp;#39;s example - Gist is a simple way to share snippets of text and code with others.">
  <meta name="description" content="a python web framework bottle&amp;#39;s example - Gist is a simple way to share snippets of text and code with others.">

<script src="./a python web framework bottle's example_files/api.js"></script></head>

<body class=" " style="">

  <div id="wrapper">
    

    <div id="header" class="header header-logged-out">
      <div class="container">
        <a class="header-logo-wordmark" href="https://gist.github.com/"><span class="octicon octicon-logo-gist"></span></a>

        <div class="header-actions">
          <a class="button primary" href="https://github.com/signup?return_to=gist">Sign up for a GitHub Account</a>
          <a class="button" href="https://gist.github.com/login?return_to=/Arthraim/994641" data-skip-pjax="">Sign in</a>
        </div>
      </div>
    </div>

    <div class="site-content" id="js-pjax-container" data-pjax-container="">
      <div class=" site-container js-site-container" data-url="/Arthraim/994641">
  
  <meta content="true" name="octolytics-dimension-public"><meta content="994641" name="octolytics-dimension-gist_id"><meta content="994641" name="octolytics-dimension-gist_name"><meta content="false" name="octolytics-dimension-anonymous"><meta content="133202" name="octolytics-dimension-owner_id"><meta content="Arthraim" name="octolytics-dimension-owner_login"><meta content="false" name="octolytics-dimension-forked">

<div class="pagehead repohead">
  <div class="container">
    <div class="title-actions-bar">
      <ul class="pagehead-actions">
      </ul>
      <h1 itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" class="entry-title public">
        <span class="repo-label"><span>public</span></span>
        <span class="mega-octicon octicon-gist"></span>
        <div class="meta">
          <div class="gist-author">
            <img src="./a python web framework bottle's example_files/a0eef010278ab0859ea2424aea0f1e28" width="26" height="26">
            <span class="author vcard">
                <span itemprop="title"><a href="https://gist.github.com/Arthraim">Arthraim</a></span>
            </span> /
            <strong><a href="./a python web framework bottle's example_files/a python web framework bottle's example.html" class="js-current-repository">bottle_example.py</a></strong>
          </div>
          <div class="gist-timestamp">
              <span class="datetime">Last updated <time class="js-relative-date" title="2013-06-18T17:06:47Z" datetime="2013-06-18T17:06:47Z">11 days ago</time></span>
          </div>
      </div></h1>
    </div>

  </div>
</div>



<div class="gist-description container">
  <p>a python web framework bottle's example</p>
</div>

<div class="gist container js-gist-container" data-version="c6a01a36f832d0e3acaeeac1694a28af60ac0d59">
    <div class="root-pane">
  <div class="menu-container">
    <ul class="menu gisttabs">
      <li>
        <a href="./a python web framework bottle's example_files/a python web framework bottle's example.html" class="selected">
          Gist Detail
        </a>
      </li>

        <li class="revision-count">
          <a href="https://gist.github.com/Arthraim/994641/revisions">
            Revisions
            <span class="counter">3</span>
          </a>
        </li>

        <li>
          <a href="https://gist.github.com/Arthraim/994641/stars">
            Stars
            <span class="counter">10</span>
          </a>
        </li>

        <li>
          <a href="https://gist.github.com/Arthraim/994641/forks">
            Forks
            <span class="counter">5</span>
          </a>
        </li>
    </ul>
  </div>

  <ul class="export-references">
    <li>
      <a href="https://gist.github.com/Arthraim/994641/download" class="minibutton" data-skip-pjax="true" rel="nofollow"><span class="octicon octicon-cloud-download"></span>Download Gist</a>
    </li>
    <li>
      <label for="url-field"><strong>Clone</strong> this gist</label>
      <input type="text" readonly="" spellcheck="false" class="url-field js-url-field js-cptoggle" name="url-field" value="https://gist.github.com/994641.git" data-cptoggle-display="/Arthraim/994641">
    </li>
    <li>
      <label for="embed-field"><strong>Embed</strong> this gist</label>
      <input type="text" readonly="" spellcheck="false" class="url-field js-url-field" name="embed-field" value="&lt;script src=&quot;https://gist.github.com/Arthraim/994641.js&quot;&gt;&lt;/script&gt;">
    </li>
    <li>
      <label for="link-field"><strong>Link to</strong> this gist</label>
      <input type="text" readonly="" spellcheck="false" class="url-field js-url-field" name="link-field" value="https://gist.github.com/Arthraim/994641">
    </li>
  </ul>
</div>


  <div class="column files">
        <div id="file-bottle_example-py" class="bubble">
          <div class="file-box ">
            <div class="meta">
              <div class="file-info">
                <span class="file-type-icon"><span class="octicon octicon-gist"></span></span>
                <strong class="file-name js-selectable-text">bottle_example.py</strong>
              </div>
              <div class="file-actions">
                <span class="file-language">Python</span>
                <ul class="button-group">
                  <li><a href="https://gist.github.com/Arthraim/994641#file-bottle_example-py" class="file-actions-button tooltipped downwards permalink" original-title="Permalink"><span class="octicon octicon-link"></span></a></li>
                  <li><a href="https://gist.github.com/Arthraim/994641/raw/f90ef6f438f2c2b4676e896dbd7d59eb64aa6f04/bottle_example.py" data-skip-pjax="" class="file-actions-button tooltipped downwards raw-url" original-title="View Raw"><span class="octicon octicon-code"></span></a></li>
                </ul>
              </div>
            </div>
            <div class="suppressed">
              <a class="js-show-suppressed-file">File suppressed. Click to show.</a>
            </div>
            


  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tbody><tr>
        <td class="line-numbers">
          <span class="line-number" id="file-bottle_example-py-L1" rel="file-bottle_example-py-L1">1</span>
          <span class="line-number" id="file-bottle_example-py-L2" rel="file-bottle_example-py-L2">2</span>
          <span class="line-number" id="file-bottle_example-py-L3" rel="file-bottle_example-py-L3">3</span>
          <span class="line-number" id="file-bottle_example-py-L4" rel="file-bottle_example-py-L4">4</span>
          <span class="line-number" id="file-bottle_example-py-L5" rel="file-bottle_example-py-L5">5</span>
          <span class="line-number" id="file-bottle_example-py-L6" rel="file-bottle_example-py-L6">6</span>
          <span class="line-number" id="file-bottle_example-py-L7" rel="file-bottle_example-py-L7">7</span>
          <span class="line-number" id="file-bottle_example-py-L8" rel="file-bottle_example-py-L8">8</span>
          <span class="line-number" id="file-bottle_example-py-L9" rel="file-bottle_example-py-L9">9</span>
          <span class="line-number" id="file-bottle_example-py-L10" rel="file-bottle_example-py-L10">10</span>
          <span class="line-number" id="file-bottle_example-py-L11" rel="file-bottle_example-py-L11">11</span>
          <span class="line-number" id="file-bottle_example-py-L12" rel="file-bottle_example-py-L12">12</span>
          <span class="line-number" id="file-bottle_example-py-L13" rel="file-bottle_example-py-L13">13</span>
          <span class="line-number" id="file-bottle_example-py-L14" rel="file-bottle_example-py-L14">14</span>
          <span class="line-number" id="file-bottle_example-py-L15" rel="file-bottle_example-py-L15">15</span>
          <span class="line-number" id="file-bottle_example-py-L16" rel="file-bottle_example-py-L16">16</span>
          <span class="line-number" id="file-bottle_example-py-L17" rel="file-bottle_example-py-L17">17</span>
          <span class="line-number" id="file-bottle_example-py-L18" rel="file-bottle_example-py-L18">18</span>
          <span class="line-number" id="file-bottle_example-py-L19" rel="file-bottle_example-py-L19">19</span>
          <span class="line-number" id="file-bottle_example-py-L20" rel="file-bottle_example-py-L20">20</span>
          <span class="line-number" id="file-bottle_example-py-L21" rel="file-bottle_example-py-L21">21</span>
          <span class="line-number" id="file-bottle_example-py-L22" rel="file-bottle_example-py-L22">22</span>
          <span class="line-number" id="file-bottle_example-py-L23" rel="file-bottle_example-py-L23">23</span>
          <span class="line-number" id="file-bottle_example-py-L24" rel="file-bottle_example-py-L24">24</span>
          <span class="line-number" id="file-bottle_example-py-L25" rel="file-bottle_example-py-L25">25</span>
          <span class="line-number" id="file-bottle_example-py-L26" rel="file-bottle_example-py-L26">26</span>
          <span class="line-number" id="file-bottle_example-py-L27" rel="file-bottle_example-py-L27">27</span>
          <span class="line-number" id="file-bottle_example-py-L28" rel="file-bottle_example-py-L28">28</span>
          <span class="line-number" id="file-bottle_example-py-L29" rel="file-bottle_example-py-L29">29</span>
          <span class="line-number" id="file-bottle_example-py-L30" rel="file-bottle_example-py-L30">30</span>
          <span class="line-number" id="file-bottle_example-py-L31" rel="file-bottle_example-py-L31">31</span>
          <span class="line-number" id="file-bottle_example-py-L32" rel="file-bottle_example-py-L32">32</span>
          <span class="line-number" id="file-bottle_example-py-L33" rel="file-bottle_example-py-L33">33</span>
          <span class="line-number" id="file-bottle_example-py-L34" rel="file-bottle_example-py-L34">34</span>
          <span class="line-number" id="file-bottle_example-py-L35" rel="file-bottle_example-py-L35">35</span>
          <span class="line-number" id="file-bottle_example-py-L36" rel="file-bottle_example-py-L36">36</span>
          <span class="line-number" id="file-bottle_example-py-L37" rel="file-bottle_example-py-L37">37</span>
          <span class="line-number" id="file-bottle_example-py-L38" rel="file-bottle_example-py-L38">38</span>
          <span class="line-number" id="file-bottle_example-py-L39" rel="file-bottle_example-py-L39">39</span>
          <span class="line-number" id="file-bottle_example-py-L40" rel="file-bottle_example-py-L40">40</span>
          <span class="line-number" id="file-bottle_example-py-L41" rel="file-bottle_example-py-L41">41</span>
          <span class="line-number" id="file-bottle_example-py-L42" rel="file-bottle_example-py-L42">42</span>
          <span class="line-number" id="file-bottle_example-py-L43" rel="file-bottle_example-py-L43">43</span>
          <span class="line-number" id="file-bottle_example-py-L44" rel="file-bottle_example-py-L44">44</span>
          <span class="line-number" id="file-bottle_example-py-L45" rel="file-bottle_example-py-L45">45</span>
          <span class="line-number" id="file-bottle_example-py-L46" rel="file-bottle_example-py-L46">46</span>
          <span class="line-number" id="file-bottle_example-py-L47" rel="file-bottle_example-py-L47">47</span>
          <span class="line-number" id="file-bottle_example-py-L48" rel="file-bottle_example-py-L48">48</span>
          <span class="line-number" id="file-bottle_example-py-L49" rel="file-bottle_example-py-L49">49</span>
          <span class="line-number" id="file-bottle_example-py-L50" rel="file-bottle_example-py-L50">50</span>
          <span class="line-number" id="file-bottle_example-py-L51" rel="file-bottle_example-py-L51">51</span>
          <span class="line-number" id="file-bottle_example-py-L52" rel="file-bottle_example-py-L52">52</span>
          <span class="line-number" id="file-bottle_example-py-L53" rel="file-bottle_example-py-L53">53</span>
          <span class="line-number" id="file-bottle_example-py-L54" rel="file-bottle_example-py-L54">54</span>
          <span class="line-number" id="file-bottle_example-py-L55" rel="file-bottle_example-py-L55">55</span>
          <span class="line-number" id="file-bottle_example-py-L56" rel="file-bottle_example-py-L56">56</span>
          <span class="line-number" id="file-bottle_example-py-L57" rel="file-bottle_example-py-L57">57</span>
          <span class="line-number" id="file-bottle_example-py-L58" rel="file-bottle_example-py-L58">58</span>
          <span class="line-number" id="file-bottle_example-py-L59" rel="file-bottle_example-py-L59">59</span>
          <span class="line-number" id="file-bottle_example-py-L60" rel="file-bottle_example-py-L60">60</span>
          <span class="line-number" id="file-bottle_example-py-L61" rel="file-bottle_example-py-L61">61</span>
          <span class="line-number" id="file-bottle_example-py-L62" rel="file-bottle_example-py-L62">62</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-bottle_example-py-LC1" style=""><span class="c">#coding: utf-8</span></div><div class="line" id="file-bottle_example-py-LC2" style=""><span class="kn">from</span> <span class="nn">bottle</span> <span class="kn">import</span> <span class="n">route</span><span class="p">,</span> <span class="n">error</span><span class="p">,</span> <span class="n">post</span><span class="p">,</span> <span class="n">get</span><span class="p">,</span> <span class="n">run</span><span class="p">,</span> <span class="n">static_file</span><span class="p">,</span> <span class="n">abort</span><span class="p">,</span> <span class="n">redirect</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">template</span></div><div class="line" id="file-bottle_example-py-LC3" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC4" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC5" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/index.html'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC6" style=""><span class="k">def</span> <span class="nf">index</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC7" style="">    <span class="k">return</span> <span class="s">'&lt;a href="/hello"&gt;Go to Hello World page&lt;/a&gt;'</span></div><div class="line" id="file-bottle_example-py-LC8" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC9" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/hello'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC10" style=""><span class="k">def</span> <span class="nf">hello</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC11" style="">    <span class="k">return</span> <span class="s">'&lt;h1&gt;HELLO WOLRD&lt;/h1&gt;'</span></div><div class="line" id="file-bottle_example-py-LC12" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC13" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/hello/:name'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC14" style=""><span class="k">def</span> <span class="nf">hello_name</span><span class="p">(</span><span class="n">name</span><span class="p">):</span></div><div class="line" id="file-bottle_example-py-LC15" style="">    <span class="n">page</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'page'</span><span class="p">,</span> <span class="s">'1'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC16" style="">    <span class="k">return</span> <span class="s">'&lt;h1&gt;HELLO </span><span class="si">%s</span><span class="s"> &lt;br/&gt;(</span><span class="si">%s</span><span class="s">)&lt;/h1&gt;'</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">page</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC17" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC18" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/static/:filename'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC19" style=""><span class="k">def</span> <span class="nf">serve_static</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span></div><div class="line" id="file-bottle_example-py-LC20" style="">    <span class="k">return</span> <span class="n">static_file</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s">'/home/arthur/workspace/my_python_codes/src/'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC21" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC22" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/raise_error'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC23" style=""><span class="k">def</span> <span class="nf">raise_error</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC24" style="">    <span class="n">abort</span><span class="p">(</span><span class="mi">404</span><span class="p">,</span> <span class="s">"error..."</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC25" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC26" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/redirect'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC27" style=""><span class="k">def</span> <span class="nf">redirect_to_hello</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC28" style="">    <span class="n">redirect</span><span class="p">(</span><span class="s">'/hello'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC29" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC30" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/ajax'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC31" style=""><span class="k">def</span> <span class="nf">ajax_response</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC32" style="">    <span class="k">return</span> <span class="p">{</span><span class="s">'dictionary'</span><span class="p">:</span> <span class="s">'you will see ajax response right? Content-Type will be "application/json"'</span><span class="p">}</span></div><div class="line" id="file-bottle_example-py-LC33" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC34" style=""><span class="nd">@error</span><span class="p">(</span><span class="mi">404</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC35" style=""><span class="k">def</span> <span class="nf">error404</span><span class="p">(</span><span class="n">error</span><span class="p">):</span></div><div class="line" id="file-bottle_example-py-LC36" style="">    <span class="k">return</span> <span class="s">'404 error !!!!!'</span></div><div class="line" id="file-bottle_example-py-LC37" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC38" style=""><span class="nd">@get</span><span class="p">(</span><span class="s">'/upload'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC39" style=""><span class="k">def</span> <span class="nf">upload_view</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC40" style="">    <span class="k">return</span> <span class="s">"""</span></div><div class="line" id="file-bottle_example-py-LC41" style=""><span class="s">        &lt;form action="/upload" method="post" enctype="multipart/form-data"&gt;</span></div><div class="line" id="file-bottle_example-py-LC42" style=""><span class="s">          &lt;input type="text" name="name" /&gt;</span></div><div class="line" id="file-bottle_example-py-LC43" style=""><span class="s">          &lt;input type="file" name="data" /&gt;</span></div><div class="line" id="file-bottle_example-py-LC44" style=""><span class="s">          &lt;input type="submit" name="submit" value="upload now" /&gt;</span></div><div class="line" id="file-bottle_example-py-LC45" style=""><span class="s">        &lt;/form&gt;</span></div><div class="line" id="file-bottle_example-py-LC46" style=""><span class="s">        """</span>    </div><div class="line" id="file-bottle_example-py-LC47" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC48" style=""><span class="nd">@post</span><span class="p">(</span><span class="s">'/upload'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC49" style=""><span class="k">def</span> <span class="nf">do_upload</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC50" style="">    <span class="n">name</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">forms</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'name'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC51" style="">    <span class="n">data</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">files</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'data'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC52" style="">    <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></div><div class="line" id="file-bottle_example-py-LC53" style="">        <span class="n">raw</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c"># small files =.=</span></div><div class="line" id="file-bottle_example-py-LC54" style="">        <span class="n">filename</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">filename</span></div><div class="line" id="file-bottle_example-py-LC55" style="">        <span class="k">return</span> <span class="s">"Hello </span><span class="si">%s</span><span class="s">! You uploaded </span><span class="si">%s</span><span class="s"> (</span><span class="si">%d</span><span class="s"> bytes)."</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">raw</span><span class="p">))</span></div><div class="line" id="file-bottle_example-py-LC56" style="">    <span class="k">return</span> <span class="s">"You missed a field."</span></div><div class="line" id="file-bottle_example-py-LC57" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC58" style=""><span class="nd">@route</span><span class="p">(</span><span class="s">'/tpl'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC59" style=""><span class="k">def</span> <span class="nf">tpl</span><span class="p">():</span></div><div class="line" id="file-bottle_example-py-LC60" style="">    <span class="k">return</span> <span class="n">template</span><span class="p">(</span><span class="s">'test'</span><span class="p">)</span></div><div class="line" id="file-bottle_example-py-LC61" style="">&nbsp;</div><div class="line" id="file-bottle_example-py-LC62" style=""><span class="n">run</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">'localhost'</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">8000</span><span class="p">,</span> <span class="n">reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span></div></pre>
        </td>
      </tr>
    </tbody></table>
  </div>

          </div>
        </div>
    <div id="comments" class="new-comments">
      
<div class="discussion-bubble js-comment-container">
  <img class="discussion-bubble-avatar" width="48" height="48" src="./a python web framework bottle's example_files/ce111c380dfd4f06786299adae06b2c8">
  <div class="discussion-bubble-content bubble">
    <div class="discussion-bubble-inner">

      <div class="comment js-comment " id="comment-229321">
        <div class="comment-header normal-comment-header">
          <a href="https://gist.github.com/Arthraim/994641#" class="comment-type-icon octicon octicon-comment"></a>
          <a href="https://gist.github.com/spil-dave" class="comment-header-author">spil-dave</a>
          <span class="comment-header-action-text">
            <span id="gistcomment-229321">
              <a href="https://gist.github.com/Arthraim/994641/#comment-229321">commented</a></span>
          </span>
          <span class="comment-header-right">
            <span id="gistcomment-229321">
              <a href="https://gist.github.com/Arthraim/994641/#comment-229321" class="comment-header-date">
                <time class="js-relative-date" title="2012-04-05T09:01:58Z" datetime="2012-04-05T09:01:58Z">a year ago</time>
              </a>
            </span>
          </span>
        </div>


        <div class="comment-content">
          <div class="edit-comment-hide">
            <!-- <div class="comment-form-error">There has been an error</div> -->
            <div class="comment-body markdown-body markdown-format js-comment-body">
                <p>Thank you for the your code sample, it was very useful!<br>
There is a minor typo in function upload_view():<br>
In the form, mutipart should be muLtipart.   The error appears on function do_upload() calls. <br>
Because the form is not multipart,  data = request.files.get('data') returns None.<br>
Hope this helps, cheers, Dave</p>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
</div>

<div class="discussion-bubble js-comment-container">
  <img class="discussion-bubble-avatar" width="48" height="48" src="./a python web framework bottle's example_files/a0eef010278ab0859ea2424aea0f1e28">
  <div class="discussion-bubble-content bubble">
    <div class="discussion-bubble-inner">

      <div class="comment js-comment " id="comment-229348">
        <div class="comment-header normal-comment-header">
          <a href="https://gist.github.com/Arthraim/994641#" class="comment-type-icon octicon octicon-comment"></a>
          <a href="https://gist.github.com/Arthraim" class="comment-header-author">Arthraim</a>
          <span class="comment-header-action-text">
            <span id="gistcomment-229348">
              <a href="https://gist.github.com/Arthraim/994641/#comment-229348">commented</a></span>
          </span>
          <span class="comment-header-right">
            <span id="gistcomment-229348">
              <a href="https://gist.github.com/Arthraim/994641/#comment-229348" class="comment-header-date">
                <time class="js-relative-date" title="2012-04-05T09:12:14Z" datetime="2012-04-05T09:12:14Z">a year ago</time>
              </a>
            </span>
          </span>
        </div>


        <div class="comment-content">
          <div class="edit-comment-hide">
            <!-- <div class="comment-form-error">There has been an error</div> -->
            <div class="comment-body markdown-body markdown-format js-comment-body">
                <p>You're right! Careless mistake. Thanks <a href="https://gist.github.com/spil-dave" class="user-mention">@spil-dave</a>.</p>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
</div>

<div class="discussion-bubble js-comment-container">
  <img class="discussion-bubble-avatar" width="48" height="48" src="./a python web framework bottle's example_files/a3868ed7724b918d2630b3cc1d475ed5">
  <div class="discussion-bubble-content bubble">
    <div class="discussion-bubble-inner">

      <div class="comment js-comment " id="comment-306014">
        <div class="comment-header normal-comment-header">
          <a href="https://gist.github.com/Arthraim/994641#" class="comment-type-icon octicon octicon-comment"></a>
          <a href="https://gist.github.com/fcourchesne" class="comment-header-author">fcourchesne</a>
          <span class="comment-header-action-text">
            <span id="gistcomment-306014">
              <a href="https://gist.github.com/Arthraim/994641/#comment-306014">commented</a></span>
          </span>
          <span class="comment-header-right">
            <span id="gistcomment-306014">
              <a href="https://gist.github.com/Arthraim/994641/#comment-306014" class="comment-header-date">
                <time class="js-relative-date" title="2012-05-06T22:14:08Z" datetime="2012-05-06T22:14:08Z">a year ago</time>
              </a>
            </span>
          </span>
        </div>


        <div class="comment-content">
          <div class="edit-comment-hide">
            <!-- <div class="comment-form-error">There has been an error</div> -->
            <div class="comment-body markdown-body markdown-format js-comment-body">
                <p>Very useful, thank you.</p>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
</div>

<div class="discussion-bubble js-comment-container">
  <img class="discussion-bubble-avatar" width="48" height="48" src="./a python web framework bottle's example_files/f9bf23dbd30011a73db9b0bd79409094">
  <div class="discussion-bubble-content bubble">
    <div class="discussion-bubble-inner">

      <div class="comment js-comment " id="comment-668374">
        <div class="comment-header normal-comment-header">
          <a href="https://gist.github.com/Arthraim/994641#" class="comment-type-icon octicon octicon-comment"></a>
          <a href="https://gist.github.com/careyshan" class="comment-header-author">careyshan</a>
          <span class="comment-header-action-text">
            <span id="gistcomment-668374">
              <a href="https://gist.github.com/Arthraim/994641/#comment-668374">commented</a></span>
          </span>
          <span class="comment-header-right">
            <span id="gistcomment-668374">
              <a href="https://gist.github.com/Arthraim/994641/#comment-668374" class="comment-header-date">
                <time class="js-relative-date" title="2012-12-24T17:42:17Z" datetime="2012-12-24T17:42:17Z">6 months ago</time>
              </a>
            </span>
          </span>
        </div>


        <div class="comment-content">
          <div class="edit-comment-hide">
            <!-- <div class="comment-form-error">There has been an error</div> -->
            <div class="comment-body markdown-body markdown-format js-comment-body">
                <p>This is very useful code, Just one quick question. How do you access a file from the do_upload function?<br>
Many thanks for your help.</p>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
</div>

<div class="discussion-bubble js-comment-container">
  <img class="discussion-bubble-avatar" width="48" height="48" src="./a python web framework bottle's example_files/58a18384a1905810be9ab7bf4bd5ffe3">
  <div class="discussion-bubble-content bubble">
    <div class="discussion-bubble-inner">

      <div class="comment js-comment " id="comment-846509">
        <div class="comment-header normal-comment-header">
          <a href="https://gist.github.com/Arthraim/994641#" class="comment-type-icon octicon octicon-comment"></a>
          <a href="https://gist.github.com/kaklis" class="comment-header-author">kaklis</a>
          <span class="comment-header-action-text">
            <span id="gistcomment-846509">
              <a href="https://gist.github.com/Arthraim/994641/#comment-846509">commented</a></span>
          </span>
          <span class="comment-header-right">
            <span id="gistcomment-846509">
              <a href="https://gist.github.com/Arthraim/994641/#comment-846509" class="comment-header-date">
                <time class="js-relative-date" title="2013-06-17T11:58:42Z" datetime="2013-06-17T11:58:42Z">13 days ago</time>
              </a>
            </span>
          </span>
        </div>


        <div class="comment-content">
          <div class="edit-comment-hide">
            <!-- <div class="comment-form-error">There has been an error</div> -->
            <div class="comment-body markdown-body markdown-format js-comment-body">
                <p>Thank you for these great snippets! </p>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
</div>

    </div>
      <p class="uncommentable"><span class="octicon octicon-alert"></span> Please <a href="https://gist.github.com/login?return_to=/Arthraim/994641" rel="nofollow">sign in</a> to comment on this gist.</p>
  </div>
</div>

  <div class="context-overlay"></div>
</div>

    </div>
    <div class="slow-loading-overlay"></div>
  </div>

  <div id="ajax-error-message" class="flash flash-error">
    <div class="container">
      <span class="octicon octicon-alert"></span>
      Something went wrong with that request. Please try again.
      <a href="https://gist.github.com/Arthraim/994641#" class="octicon octicon-remove-close ajax-error-dismiss"></a>
    </div>
  </div>

  <footer>
    <div id="footer">
  <div class="container clearfix">

    <!-- Served fresh by github-fe103-cp1-prd.iad.github.net -->
    <p class="right">© 2013 GitHub Inc. All rights reserved.</p>
    <a class="left" href="https://gist.github.com/">
      <span class="mega-octicon octicon-mark-github"></span>
    </a>
    <ul id="legal">
      <li><a href="https://github.com/blog">The GitHub Blog</a></li>
      <li><a href="mailto:support@github.com">Support</a></li>
      <li><a href="https://github.com/contact">Contact</a></li>
    </ul>

  </div><!-- /.container -->
</div><!-- /.#footer -->

  </footer>



</body></html>